package com.yanliang.demo.controller;

import com.yanliang.demo.service.IDemoService;
import com.yanliang.mvcframework.annotations.MyAutowired;
import com.yanliang.mvcframework.annotations.MyController;
import com.yanliang.mvcframework.annotations.MyRequestMapping;
import com.yanliang.mvcframework.annotations.MySecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@MyController
@MyRequestMapping("/demo")
public class DemoController {

    @MyAutowired
    private IDemoService demoService;

    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param name
     * @return
     */
    @MyRequestMapping("/query")
    public String query(HttpServletRequest request, HttpServletResponse response, String name) {
        return demoService.get(name);
    }

    @MyRequestMapping("/handler01")
    @MySecurity(value = {"yanliang1", "yanliang2"})
    public void handler01(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.getWriter().write(String.format("%s 访问了 handler01", req.getParameter("username")));
    }

    @MyRequestMapping("/handler02")
    @MySecurity(value = {"yanliang3", "yanliang4"})
    public void handler02(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.getWriter().write(String.format("%s 访问了 handler02", req.getParameter("username")));
    }
}
